package  
{
	import org.flixel.*;

	public class Fx extends FlxGroup
	{
		private var pixels:FlxGroup;
		private var jet:FlxEmitter;
		
		[Embed(source = '../assets/jets.png')] private var jetsPNG:Class;
		
		public function Fx() 
		{
			super();
			
			scrollFactor.x = 0;
			scrollFactor.y = 0;
			
			pixels = new FlxGroup();
			
			pixels.scrollFactor.x = 0;
			pixels.scrollFactor.y = 0;
			
			//	Here we create an FlxGroup containing 40 FlxEmitters, all the same, used when the aliens are shot/explode
			for (var i:int = 0; i < 40; i++)
			{
				var tempPixel:FlxEmitter = new FlxEmitter();
				tempPixel.scrollFactor.x = 0;
				tempPixel.scrollFactor.y = 0;
				tempPixel.setSize(8, 8);
				tempPixel.gravity = 200;
				tempPixel.setXSpeed(-50, 50);
				tempPixel.setYSpeed( -30, -60);
				tempPixel.setRotation(0, 0);	// VITAL!!!
				tempPixel.createSprites(Pixel, 4, 0, true, 0, 0);
				
				pixels.add(tempPixel, true);
			}
			
			//	Jet thrusters for trailing behind the ship
			jet = new FlxEmitter();
			jet.scrollFactor.x = 0;
			jet.scrollFactor.y = 0;
			jet.setSize(8, 8);
			jet.angularVelocity = 0;
			jet.gravity = 300;
			jet.setXSpeed(-30, 30);
			jet.setYSpeed(80, 120);
			jet.setRotation(0, 0);	// VITAL!!!
			jet.createSprites(jetsPNG, 40, 0, false, 0, 0);
			jet.delay = 0.01;
			jet.start(false);
			
			add(pixels, true);
			add(jet, true);
		}
		
		override public function update():void
		{
			super.update();
			
			//	We can't use jet.at(Registry.player) because we need to offset the x/y a little to make
			//	it look like the jets are coming from the bottom middle of the ship
			jet.x = Registry.player.x + 4;
			jet.y = Registry.player.y + 12;
		}
		
		public function explodeBlock(ax:int, ay:int):void
		{
			var pixel:FlxEmitter = FlxEmitter(pixels.getFirstAvail());
			
			if (pixel)
			{
				pixel.x = ax;
				pixel.y = ay;
				pixel.start(true);
			}
		}
		
	}

}